﻿using CIS.Common.Dto.Dtos.Equipments.Commands;
using CIS.Common.Grpc;
using CIS.Common.Grpc.Protos;
using CIS.Device.Common.Events;
using CIS.Device.Modules.Commons;
using CIS.Events.Contracts.Equipments;
using Grpc.Core;
using Grpc.Net.Client;
using Newtonsoft.Json;
using Prism.Commands;
using Prism.Events;
using Prism.Mvvm;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Text;
using System.Text.Json.Serialization;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Interop;

namespace CIS.Device.Modules.IndexModules.ViewModels
{
    public class IndexViewModel : BindableBase
    {        
        private readonly IEventAggregator _eventAggregator;
        public IndexViewModel(IEventAggregator eventAggregator)
        {
            _eventAggregator = eventAggregator;
        }

        private DelegateCommand sendMessage;

        public DelegateCommand SendMessage
        {
            get 
            {
                return new DelegateCommand(SendFunction);
            }
        }

        private void SendFunction()
        {
            UnitStatusChangeReportDto dto = new UnitStatusChangeReportDto();
            dto.SourceId = "3AFS12-IND";
            dto.EventName = "UnitStatusChangeReport";
            dto.UnitStatus = 1;
            dto.SubUnitCount = 0;
            dto.ReasonCode = 1001;
            GrpcMessage message = new GrpcMessage()
            {
                IsRequest = false,
                Name = dto.EventName,
                Data = JsonConvert.SerializeObject(dto)
            };
            _eventAggregator.GetEvent<ReportEvent<GrpcMessage>>().Publish(message);
        }
    }
}

